﻿var burl1 = "hangqing.ashx";
function getUrl() {
    json = 100; t = 1;
    p = $("#hidP").val();
    c = $("#hidT").val();
    t = $("#hidTy").val();
    i = 1;
    id = $("#hidCode").val();
    return "?id=" + id + "&t=" + t + "&p=" + p + "&i=" + i + "&json=" + json + "&c=" + c;
}
function getData() {
    purl = burl1 + getUrl();
    purl = purl + "&ran=" + Math.random().toString() ;
    if (isReady)
        $.getJSON(purl, dataLoaded);
    else $.getJSON(purl, dataLoadedFirst);
}
function dataLoaded(data) {
    try {
        //alert(data);
        if (data == undefined) {
            dataLoadError();
            return;
        }
        chart1.refreshData("json", data);
    } catch (ex) {
        dataLoadError();
        //alert(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }
}
function dataLoadedFirst(data) {
    //alert("dataLoadedFirst");
    try {
        if (data == undefined) {
            return;
        }
     
        firstData = data;
        chart1.refreshData("json", data);
        //alert("fasdf");
        invReady = setInterval(firstAdd, 50);

    } catch (ex) {
        invReady = setInterval(firstAdd, 50);
        //dataLoadError();
        //alert(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }
}
function firstAdd() {
    if (chart1.refreshData("json", firstData)) {
        //alert("clearFirst");
        if (invReady) clearInterval(invReady);
        isReady = true;
    }
}

function dataLoadError() {
    if (inv) clearInterval(getData, 5 * 1000);
    $("#txtCode").val("");
    alert("获得数据出错，请重新输入股票代码！");
}